package com.hrd.service.impl;

import com.hrd.common.util.bean.ServiceResult;
import com.hrd.datasource.DatabaseContextHolder;
import com.hrd.mybatis.bean.auto.HrdSynchLog;
import com.hrd.mybatis.bean.auto.HrdSynchLogExample;
import com.hrd.service.SynchLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: wangpeng
 * @Date: 2022/1/17 11:16
 * @Description:
 */
@Service
public class SynchLogServicImpl extends BaseServiceImpl implements SynchLogService {
    @Override
    public ServiceResult<List<HrdSynchLog>> list(HrdSynchLog form) {
        DatabaseContextHolder.setCustomerType(DatabaseContextHolder.DATA_SOURCE_MYSQL);
        ServiceResult<List<HrdSynchLog>> result = new ServiceResult<>();
        HrdSynchLogExample example = new HrdSynchLogExample();
        HrdSynchLogExample.Criteria criteria  = example.createCriteria();
        if (StringUtils.isNotBlank(form.getSynchType())){
            criteria.andSynchTypeEqualTo(form.getSynchType());
        }
        example.setOrderByClause("synch_time desc");
        List<HrdSynchLog> hrdSynchLogs = this.hrdSynchLogMapper.selectByExample(example);
        result.setResult(hrdSynchLogs);
        result.setSuccess(true);
        return result;
    }
}
